home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / bbs / cit_src_7H21.lha / domains.c < prev    next >
C/C++ Source or Header  |  1997-08-14  |  37KB  |  1,330 lines

  1. /*
  2. *                               Domains.C
  3. *
  4. * Domain handing code.
  5. */
  6. #include "ctdl.h"
  7. #include "2ndfmt.h"
  8. /*
  9. *                               history
  10. *
  11. * 90May20 HAW  Created.
  12. */
  13. /*
  14. *                               contents
  15. *
  16. *       DomainInit()            Initializes domains.  Call once only.
  17. *       EatDomainLine()         Eats a line from map.sys.
  18. *       CheckDomain()           Helps search lists for a domain.
  19. *       CmpDomain()             Helps sort a list of domains.
  20. *       DomainMailFileName()    Creates a filename for mail for a domain.
  21. *       GetDomain()             Create a domain entry for domain mail.
  22. *       UpdateMap()             Updates Map.sys.
  23. *       WriteDomainMap()        Helps write out Map.sys.
  24. *       DomainFileAddResult()   Finishes dealing with a piece of domain mail.
  25. *       RationalizeDomains()    Checks all active domains for integrity.
  26. *       DomainRationalize()     Checks a single domain for integrity.
  27. *       KillDomain()            Takes a domain out of list and disk.
  28. *       FindDomainH()           Helps find a domain handler in a list.
  29. *       EatDomainH()            Eats a line from ctdldmhd.sys.
  30. *       ViaHandle()             Handles a 'via' line from ctdldmhd.sys.
  31. *       HandleExistingDomain()  Process a domain we serve.
  32. *       SetCallout()            Sets callout flags depending on domains.
  33. *       SetUpCallOut()          Finds direction to sling domain mail.
  34. *       CallOutWork()           Work fn to find direction ...
  35. *       ClearSearched()         Clears a search marker for each domain.
  36. *       DomainOut()             Manages transmission of domain mail.
  37. *       SendDomainMail()        Does actual work of transmitting domain mail.
  38. *       SystemInSecondary()     Check for name in secondary list(s).
  39. *       SearchSecondary()       Work fn for above.
  40. *       EatCosts()              Eat a line from ctdlcost.sys.
  41. *       FindCost()              Helps find the cost for a given domain.
  42. *       WriteDomainContents()   Handles .EN? in Mail.
  43. *       DomainLog()             Handles the file DOMAIN.LOG.
  44. *       RouteHere()             Is domain mail meant for here?
  45. *       LocalName()             Is given system local?
  46. *       lifo()                  Last in First Out fn for the lists.
  47. */
  48. #define MAPSYS          "map.sys"
  49. #define WeServe(x)      SearchList(&Serves, x)
  50. /*
  51. * Required Global Variables
  52. */
  53. /*
  54. * DomainDir
  55. *
  56. * Variables of this sort define the mapping between a domain name and the
  57. * directory containing outstanding mail bound for that domain.  Typically,
  58. * a domain with no mail will not have an allocated variable.
  59. *
  60. * UsedFlag - a temporary flag indicating that domain mail was sent during
  61. * the last network connection.  Used for performance reasons.
  62. *
  63. * Domain - The name of the domain represented by this record.
  64. *
  65. * MapDir - The "name" of the directory containing the mail for this domain.
  66. * This is a number; each domain is given a unique number amongst those
  67. * active, starting with 0.  When access to the mail is desired, this number
  68. * is used to form the name.
  69. *
  70. * HighFile - The next file name (also formed from numbers starting at 0) to
  71. * use for incoming mail for this domain.
  72. *
  73. * TargetSlot - Index into CtdlNet.Sys indicating the system to pass this mail
  74. * to.  When we're connected with a system and its call out flags indicate
  75. * domain mail is bound for it, we use this flag to quickly find if this
  76. * domain is bound for the current node connection.  The flag is set when
  77. * the system initially comes up (or the record is created) by checking
  78. * against the contents of CTDLDMHD.SYS.
  79. */
  80. typedef struct
  81.   {
  82.   char   UsedFlag;      /* indicates domain was sent during last call */
  83.   label  Domain;                /* name */
  84.   UNS_16 MapDir;                /* dirnum */
  85.   UNS_16 HighFile;      /* next filename */
  86.   int    TargetSlot;    /* who do we pass this stuff on to */
  87.  
  88.   }
  89. DomainDir;
  90. DomainDir *GetDomain(char *DName, char create);
  91. /*
  92. * DomainHandler
  93. *
  94. * Defines a domain handler.  Records of this type are read in from
  95. * ctdldmhd.sys and its brethren.
  96. *
  97. * domain - Name of the domain.
  98. *
  99. * nodeId - ID of the domain server for the domain.
  100. *
  101. * searched - Temporary flag indicating if the attempt to trace the next
  102. * system to attempt to find in CtdlNet.Sys has already been checked.  Lets
  103. * us avoid infinite loops.
  104. *
  105. * via - A hint on how to connect to this system.
  106. */
  107. typedef struct Dh
  108.   {
  109.   char          *domain;
  110.   char          *nodeId;
  111.   char          searched;       /* avoids infinite loops        */
  112.   struct Dh     *via;           /* how to reach this domain     */
  113.  
  114.   }
  115. DomainHandler;
  116. /*
  117. * Some useful static functions.
  118. */
  119. static void  WriteDomainMap(DomainDir *data);
  120. static void  KillDomain(int *MapDir);
  121. static void  DomainRationalize(DomainDir *data);
  122. static void *FindDomainH(DomainHandler *data, char *name);
  123. static void *EatDomainH(char *line);
  124. static void  DomainLog(char *str);
  125. static void *EatCosts(char *line);
  126. static void *CheckDomain(DomainDir *d, char *str);
  127.        void *EatDomainLine(char *line);
  128.        int   CmpDomain(DomainDir *s, DomainDir *t);
  129. static int SetUpCallOut(char *DName);
  130. static int CallOutWork(char *DName);
  131. static int lifo(void);
  132. static void *ViaHandle(char *line);
  133. /*
  134. * List of domain handlers -- source: CTDLDMHD.SYS, CTDLDMHD.LCL.
  135. */
  136. static SListBase DomainHandlers =
  137.   {
  138.   NULL, FindDomainH, (int (*)(void *, void *))lifo, free, EatDomainH
  139.  
  140.   };
  141. /*
  142. * List of costs for domains (from ctdlcost.sys).
  143. */
  144. static SListBase Costs =
  145.   {
  146.   NULL, ChkStrtoN, NULL, NULL, EatCosts
  147.  
  148.   };
  149. /*
  150. * Current domain mail in #DOMAINAREA -- map of directories to domain names.
  151. */
  152. SListBase DomainMap    =
  153.   {
  154.   NULL, CheckDomain, CmpDomain, free, EatDomainLine
  155.  
  156.   };
  157. char *DomainFlags      = NULL;
  158. UNS_16 UnknownCost     = 1;
  159. extern CONFIG    cfg;
  160. extern NetBuffer netBuf, netTemp;
  161. extern NetTable  *netTab;
  162. extern FILE      *upfd, *netMisc, *netLog;
  163. extern int       thisNet;
  164. extern MessageBuffer   msgBuf;
  165. extern logBuffer logBuf;
  166. extern label     HomeId;
  167. extern char      *READ_ANY, *WRITE_TEXT;
  168. extern int       RMcount;
  169. extern SListBase Serves;
  170. extern char      inNet;
  171. /*
  172. * This code is responsible for managing the domain part of Citadel-86.
  173. *
  174. * DOMAIN DIRECTORY:
  175. *    The domain directory consists of a single file and a collection of
  176. * directories.
  177. *
  178. * MAP.SYS: this contains a mapping between the directory names and the
  179. * domain mail they purport to store.  Format:
  180. *
  181. * <number><space><domain><highest filename>
  182. *
  183. * DIRECTORIES (1, 2,...): these contain the actual outgoing mail, plus a file
  184. * named "info" which will hold the name of the domain (for rebuilding
  185. * purposes).
  186. */
  187. /*
  188. * DomainInit()
  189. *
  190. * This function initializes the domain stuff.  It's called from NetInit(),
  191. * addNetNode(), and from RationalizeDomains, so it has to open the relevant
  192. * files only once.
  193. *
  194. * Appropriate lists are created, call out flags set, etc.
  195. */
  196. void DomainInit(char FirstTime)
  197.   {
  198.   void HandleExistingDomain(), SetCallout();
  199.   SYS_FILE temp;
  200.   if (FirstTime)
  201.     {
  202.     makeSysName(temp, MAPSYS, &cfg.domainArea);
  203.     MakeList(&DomainMap, temp, NULL);
  204.     makeSysName(temp, "ctdlcost.sys", &cfg.netArea);
  205.     MakeList(&Costs, temp, NULL);
  206.     makeSysName(temp, "ctdldmhd.sys", &cfg.netArea);
  207.     MakeList(&DomainHandlers, temp, NULL);
  208.     makeSysName(temp, "ctdldmhd.lcl", &cfg.netArea);
  209.     MakeList(&DomainHandlers, temp, NULL);
  210.     /* now we should scan for any domain we serve, and if any are there */
  211.     /* we need to arrange to send that mail to their recipients.        */
  212.     RunList(&DomainMap, HandleExistingDomain);
  213.     RationalizeDomains();
  214.  
  215.     }
  216.   else
  217.   if (DomainFlags != NULL) free(DomainFlags);
  218.   if (cfg.netSize != 0)
  219.   DomainFlags = GetDynamic(cfg.netSize);        /* auto-zeroed */
  220.   /* This will also set the temporary call out flags, eh?               */
  221.   RunList(&DomainMap, SetCallout);
  222.  
  223.   }
  224. /*
  225. * EatDomainLine()
  226. *
  227. * This function parses a line from map.sys.  Map.sys is kept in the
  228. * #DOMAINAREA and maps the from the name of each domain with outstanding
  229. * mail and the directory it resides in.  Directories are numerically
  230. * designated.  Format of each line is
  231. *
  232. * <directory name> <domain name> <last file number>
  233. *
  234. * This function, since it's used by calls to MakeList, returns a void pointer
  235. * to the assembled data structure.
  236. */
  237. void *EatDomainLine(char *line)
  238.   {
  239.   DomainDir *data;
  240.   char *c;
  241.   data = GetDynamic(sizeof *data);
  242.   data->UsedFlag   = FALSE;
  243.   data->TargetSlot = -1;
  244.   if ((c = strchr(line, ' ')) == NULL)
  245.     {
  246.     free(data);
  247.     return NULL;
  248.  
  249.     }
  250.   *c++ = 0;
  251.   data->MapDir = atoi(line);
  252.   line = c;
  253.   if ((c = strchr(line, ' ')) == NULL)
  254.     {
  255.     free(data);
  256.     return NULL;
  257.  
  258.     }
  259.   *c++ = 0;
  260.   strCpy(data->Domain, line);
  261.   data->HighFile = atoi(c);
  262.   return data;
  263.  
  264.   }
  265. static char CheckNumber = FALSE;        /* double duty switcheroonie    */
  266. /*
  267. * CheckDomain()
  268. *
  269. * This is used to look for a domain in a list.  The search can either be on
  270. * the directory number or the domain name.
  271. */
  272. static void *CheckDomain(DomainDir *d, char *str)
  273.   {
  274.   int *i;
  275.   if (!CheckNumber)
  276.     {
  277.     if (strCmpU(d->Domain, str) == SAMESTRING) return d;
  278.  
  279.     }
  280.   else
  281.     {
  282.     i = (int *) str;
  283.     if (*i == d->MapDir) return d;
  284.  
  285.     }
  286.   return NULL;
  287.  
  288.   }
  289. /*
  290. * CmpDomain()
  291. *
  292. * This function is used in the list of domains with mail to keep the domains
  293. * in * numerical order.  The list is kept in numerical order to make MAP.SYS
  294. * a bit more tractable.
  295. */
  296. int CmpDomain(DomainDir *s, DomainDir *t)
  297.   {
  298.   return (int)(s->MapDir - t->MapDir);
  299.  
  300.   }
  301. /*
  302. * DomainMailFileName()
  303. *
  304. * This function is called when FR 9 has been received: someone wants to send
  305. * us routemail with a domain attached.  We are responsible for creating a
  306. * good filename for it, setting flags etc.  Return REFUSE if we can't accept
  307. * mail (for fatal or other reasons), LOCALROUTE if we are the domain server
  308. * and we know the target, OURS if we are the target, DOMAINFILE if we need
  309. * to store the file in a domain directory.
  310. * NB: the caller of this function provides security.
  311. * See DomainFileResult().
  312. * NB: this can also be called for local users sending domain mail
  313. */
  314. char DomainMailFileName(DOMAIN_FILE buffer, label DName, label NodeId,
  315. label NodeName)
  316.   {
  317.   DomainDir *data;
  318.   char temp[10];
  319.   /*
  320.   * The first clause of this if statement is necessary for the following
  321.   * scenario.  If we're in net mode, suppose the caller is conveying
  322.   * domain mail which, as it happens, it will be the route for the
  323.   * final leg of the mail.  (Yes, this actually happened in practice --
  324.   * an LD node was accessible only via a local node to the hub.)  Now,
  325.   * if this if isn't structured this way, when the incoming domain mail
  326.   * is deciphered, it will be assigned to this node WHILE the call is
  327.   * active, including the activation of the mail routing flag.  When the
  328.   * call terminates, these same flags will be turned OFF.  Net result
  329.   * (if you'll pardon the pun) is that R*.* files will be left in #NETAREA
  330.   * and will NOT be delivered.  Tsk tsk.  Therefore, in doResults(),
  331.   * a call to RationalizeDomains() is made which will clean up the domain
  332.   * directories after a call.
  333.   */
  334.   if (cfg.BoolFlags.debug)
  335.     {
  336.     splitF(netLog, "DomainMail(%d, %s, %s, %s)\n",buffer,DName,NodeId,NodeName);
  337.     };
  338.  
  339.   if (inNet == NON_NET && WeServe(DName) != NULL)
  340.     {
  341.     /* since we're server, we don't search the secondary lists */
  342.     if (FindTheNode(NodeId, NodeName))
  343.       {
  344.       if (netTemp.nbflags.RouteTo)
  345.         {
  346.         strCpy(NodeId, netTemp.netId);
  347.         if (cfg.BoolFlags.debug)
  348.           {
  349.           splitF(netLog, "result LOCALROUTE: NodeId=%s\n",NodeId);
  350.           };
  351.         return LOCALROUTE;
  352.  
  353.         }
  354.  
  355.       }
  356.     /*
  357.     * don't return if either conditional fails.  if we don't know
  358.     * about the node, still accept the mail for delivery, and see
  359.     * the use of HandleExistingDomain(), which is called each time
  360.     * the system is brought up.  If it's a node we know about but
  361.     * don't like, accept the mail anyways -- just in case we changes
  362.     * our mindses.  if we don't, well, hey, too bad.
  363.     */
  364.  
  365.     }
  366.   /*
  367.   * rare, but possible case - mail meant for us but we don't serve the
  368.   * domain, it's just getting routed via us.  this also picks up all
  369.   * cases where domain mail is being sent to the domain-server.
  370.   */
  371.   NormStr(NodeId);
  372.   if (RouteHere(NodeId, NodeName, DName))
  373.     {
  374.     if (cfg.BoolFlags.debug)
  375.       {
  376.       splitF(netLog, "result Ours\n");
  377.       };
  378.     return OURS;
  379.  
  380.     }
  381.   /* ok, we need to store it in its proper domain */
  382.   data = GetDomain(DName, TRUE);        /* GetDomain() creates, etc.    */
  383.   sPrintf(temp, "%d", data->HighFile++);
  384.   MakeDomainFileName(buffer, data->MapDir, temp);
  385.   UpdateMap();
  386.   return DOMAINFILE;
  387.  
  388.   }
  389. static FILE *fd;
  390. /*
  391. * GetDomain()
  392. *
  393. * This function is used to find the given domain in the installation's
  394. * current outstanding mail.  If no such domain exists, then create the
  395. * data structure and the directory entry.  In either case, return a pointer
  396. * to the appropriate record.  This should never return NULL.
  397. */
  398. DomainDir *GetDomain(char *DName, char create)
  399.   {
  400.   DomainDir *data;
  401.   int i;
  402.   DOMAIN_FILE buf;
  403.   if ((data = SearchList(&DomainMap, DName)) == NULL)
  404.     {
  405.     if (!create) return NULL;
  406.     /* create it */
  407.     data = GetDynamic(sizeof *data);
  408.     data->UsedFlag = FALSE;
  409.     strCpy(data->Domain, DName);
  410.     data->HighFile = 0;
  411.     CheckNumber = TRUE;
  412.     for (i = 0; i < 10000; i++)
  413.     if (SearchList(&DomainMap, &i) == NULL) break;
  414.     data->MapDir = i;
  415.     AddData(&DomainMap, data, NULL, FALSE);
  416.     MakeDomainDirectory(i);
  417.     MakeDomainFileName(buf, data->MapDir, "info");
  418.     if ((fd = safeopen(buf, WRITE_TEXT)) != NULL)
  419.       {
  420.       fprintf(fd, "%s", DName);
  421.       fclose(fd);
  422.  
  423.       }
  424.     CheckNumber = FALSE;
  425.     /* UpdateMap();        don't update -- let caller do it */
  426.  
  427.     }
  428.   return data;
  429.  
  430.   }
  431. /*
  432. * UpdateMap()
  433. *
  434. * This function is charged with updating MAP.SYS with new information.
  435. * Most of the work is done in WriteDomainMap().
  436. */
  437. void UpdateMap()
  438.   {
  439.   SYS_FILE temp;
  440.   void WriteDomainMap();
  441.   makeSysName(temp, MAPSYS, &cfg.domainArea);
  442.   if ((fd = safeopen(temp, WRITE_TEXT)) != NULL)
  443.     {
  444.     RunList(&DomainMap, WriteDomainMap);
  445.     fclose(fd);
  446.  
  447.     }
  448.  
  449.   }
  450. /*
  451. * WriteDomainMap()
  452. *
  453. * This writes out an entry of the domain map.
  454. */
  455. static void WriteDomainMap(DomainDir *data)
  456.   {
  457.   fprintf(fd, "%d %s %d\n", data->MapDir, data->Domain, data->HighFile);
  458.  
  459.   }
  460. /*
  461. * DomainFileAddResult()
  462. *
  463. * This function handles the result of a domain file addition.  This is paired
  464. * with DomainMailFileName() and should always be called after it has been
  465. * used to give out results.
  466. */
  467. void DomainFileAddResult(label DName, label system, label NodeId, char result)
  468.   {
  469.   DomainDir *data;
  470.   DOMAIN_FILE buf;
  471.   char work[100];
  472.   if ((data = GetDomain(DName, FALSE)) == NULL)
  473.     {
  474.     printf("URP IN DOMAINS!");
  475.     return;
  476.  
  477.     }
  478.   if (result == DOMAIN_SUCCESS)
  479.     {
  480.     if ((data->TargetSlot = SetUpCallOut(DName)) == ERROR)
  481.       {
  482.       #ifdef ROUTING_THIS_WAY
  483.       if (WeServe(DName) != NULL)
  484.         {
  485.         sPrintf(work, "Mail for unknown system %s.", system);
  486.         DomainLog(work);
  487.  
  488.         }
  489.       #else
  490.       if (WeServe(DName) != NULL)
  491.         {
  492.         /* since we're server, we don't search the secondary lists */
  493.         if (!FindTheNode(NodeId, system))
  494.           {
  495.           sPrintf(work, "Mail for unknown system %s.", system);
  496.           DomainLog(work);
  497.  
  498.           }
  499.  
  500.         }
  501.       #endif
  502.       else if (data->HighFile == 1)
  503.         {
  504.         sPrintf(work, "Don't know how to reach domain %s.", DName);
  505.         DomainLog(work);
  506.  
  507.         }
  508.  
  509.       }
  510.     return;
  511.  
  512.     }
  513.   /* failure -- assume caller erases file */
  514.   if (--data->HighFile == 0)
  515.     {
  516.     /* this indicates empty dir */
  517.     MakeDomainFileName(buf, data->MapDir, "info");
  518.     unlink(buf);
  519.     KillDomainDirectory(data->MapDir);
  520.     KillData(&DomainMap, data->Domain); /* data's ptr is now invalid */
  521.  
  522.     }
  523.   UpdateMap();
  524.  
  525.   }
  526.  
  527. static SListBase KillDomains =
  528.   {
  529.   NULL, NULL, NULL, KillDomain, NULL
  530.  
  531.   };
  532. static char Change;
  533. /*
  534. * RationalizeDomains()
  535. *
  536. * This function goes through all the domains checking for empty domains and
  537. * domains with file lists with "holes" in them (caused by a node rejecting
  538. * some routemail -- won't happen in C-86 [probably], but there's nothing in
  539. * the rules to say it can't happen).  This should be called after each network
  540. * call involving domain-mail transmissions.
  541. */
  542. void RationalizeDomains()
  543.   {
  544.   Change = FALSE;
  545.   RunList(&DomainMap, DomainRationalize);
  546.   KillList(&KillDomains);       /* clears list and kills empty domains, too */
  547.   if (Change) UpdateMap();
  548.   DomainInit(FALSE);            /* reset temp call out flags */
  549.  
  550.   }
  551. /*
  552. * DomainRationalize()
  553. *
  554. * See RationalizeDomains for detail.
  555. *
  556. * NB: this could be made far more efficient someday by keeping track of the
  557. * last gap, or keeping a list of successfully sent mail files, or ... ?
  558. */
  559. static void DomainRationalize(DomainDir *data)
  560.   {
  561.   int rover, rover2, lasthit = -1;
  562.   char temp[10], temp2[10];
  563.   DOMAIN_FILE buffer, buffer2;
  564.   if (data->UsedFlag)
  565.     {
  566.     data->UsedFlag = FALSE;
  567.     Change = TRUE;
  568.     for (rover = 0; rover < data->HighFile; rover++)
  569.       {
  570.       sPrintf(temp, "%d", rover);
  571.       MakeDomainFileName(buffer, data->MapDir, temp);
  572.       if (access(buffer, 0) != 0)
  573.         {
  574.         /* hole found */
  575.         for (rover2 = rover + 1; rover2 < data->HighFile; rover2++)
  576.           {
  577.           sPrintf(temp2, "%d", rover2);
  578.           MakeDomainFileName(buffer2, data->MapDir, temp2);
  579.           if (access(buffer2, 0) == 0)
  580.             {
  581.             /* end of gap */
  582.             rename(buffer2, buffer);    /* rename file */
  583.             lasthit = rover;
  584.  
  585.             }
  586.  
  587.           }
  588.  
  589.         }
  590.       else lasthit = rover;
  591.  
  592.       }
  593.     if (lasthit == -1)
  594.       {
  595.       MakeDomainFileName(buffer, data->MapDir, "info");
  596.       unlink(buffer);
  597.       KillDomainDirectory(data->MapDir);
  598.       /* we can't kill the data right now 'cuz we're in list processing */
  599.       /* so we'll store it and kill it later */
  600.       AddData(&KillDomains, &data->MapDir, NULL, FALSE);
  601.  
  602.       }
  603.     else data->HighFile = lasthit + 1;
  604.  
  605.     }
  606.  
  607.   }
  608. /*
  609. * KillDomain()
  610. *
  611. * Kills a domain from DomainMap.
  612. */
  613. static void KillDomain(int *MapDir)
  614.   {
  615.   CheckNumber = TRUE;
  616.   KillData(&DomainMap, MapDir); /* KABOOM! */
  617.   CheckNumber = FALSE;
  618.  
  619.   }
  620. /*
  621. * FindDomainH()
  622. *
  623. * This finds the named domain handler on the domain handler list.
  624. */
  625. static void *FindDomainH(DomainHandler *data, char *name)
  626.   {
  627.   return (strCmpU(data->domain, name) == SAMESTRING) ? data : NULL;
  628.  
  629.   }
  630. /*
  631. * EatDomainH()
  632. *
  633. * This eats a line from ctdldmhd.sys.  Notice the support for the 'via'
  634. * capability.
  635. */
  636. static void *EatDomainH(char *line)
  637.   {
  638.   DomainHandler *data;
  639.   char *c;
  640.   label temp;
  641.   if ((c = strchr(line, '#')) != NULL) *c = 0;  /* kill '#' */
  642.   NormStr(line);
  643.   if (strlen(line) <= 3) return NULL;
  644.   /* if line is of format "domain via domain" then handle that */
  645.   /* characterized by lack of colon */
  646.   if ((c = strchr(line, ':')) == NULL)
  647.     {
  648.     return ViaHandle(line);
  649.  
  650.     }
  651.   if ((c = strchr(line, ' ')) == NULL)
  652.     {
  653.     printf("WARNING: badly formed ctdldmhd.sys (1:-%s-).\n", line);
  654.     return NULL;
  655.  
  656.     }
  657.   *c++ = 0;
  658.   if ((c = strchr(c, ':')) == NULL)
  659.     {
  660.     printf("WARNING: badly formed ctdldmhd.sys (2:-%s-).\n", c);
  661.     return NULL;
  662.  
  663.     }
  664.   c++;
  665.   data = GetDynamic(sizeof *data);
  666.   data->domain = strdup(line);
  667.   normId(c, temp);
  668.   data->nodeId = strdup(temp);
  669.   return data;
  670.  
  671.   }
  672. /*
  673. * ViaHandle()
  674. *
  675. * This handles a line of format "domain via domain" for EatDomainH().  It
  676. * always returns NULL since it's only setting up the link, not creating a
  677. * new record.
  678. */
  679. static void *ViaHandle(char *line)
  680.   {
  681.   /* we're guaranteed of no comments on line */
  682.   char *space, *via;
  683.   DomainHandler *target, *viadomain;
  684.   if ((space = strchr(line, ' ')) == NULL)
  685.     {
  686.     printf("WARNING: badly formed ctdldmhd.sys (3:-%s-).\n", line);
  687.     return NULL;
  688.  
  689.     }
  690.   *space++ = 0;
  691.   if (strncmp("via ", space, 4) != 0)
  692.     {
  693.     printf("WARNING: badly formed ctdldmhd.sys (4:-%s-).\n", space);
  694.     return NULL;
  695.  
  696.     }
  697.   /* no failure guaranteed ... */
  698.   via = strchr(space, ' ') + 1;
  699.   if ((target = SearchList(&DomainHandlers, line)) != NULL)
  700.     {
  701.     if ((viadomain = SearchList(&DomainHandlers, via)) != NULL)
  702.       {
  703.       target->via = viadomain;
  704.  
  705.       }
  706.  
  707.     }
  708.   /*
  709.   * since we aren't building a new record but instead are creating a link
  710.   * between two records, so we always return NULL.
  711.   */
  712.   return NULL;
  713.  
  714.   }
  715. /*
  716. * HandleExistingDomain()
  717. *
  718. * This is called to check to see if a domain with outstanding mail happens to
  719. * be served by this installation.  If so, then that mail must be processed:
  720. * mail for this system delivered to the designated users, mail for other
  721. * systems setup to be delivered to them if they can be identified.
  722. */
  723. void HandleExistingDomain(DomainDir *dir)
  724.   {
  725.   label  temp;
  726.   int            rover;
  727.   char   *domain;
  728.   DOMAIN_FILE  buffer;
  729.   SYS_FILE     newfn;
  730.   extern FILE  *netMisc;
  731.   label  nodeId, nodeName;
  732.   char   *c, oldNet;
  733.   extern char  RCount, SCount, *R_W_ANY;
  734.   extern char  inNet;
  735.   extern int   (*NetCharSource)(void);
  736.   extern int   RouteSlot;
  737.   /*
  738.   * we save the inNet state because this code may be called during a
  739.   * non-netting state (system init), while it works better when inNet
  740.   * is in a network state.  But this code is also called during network
  741.   * processing, too, so ... we have to push and pop the state or things
  742.   * may get screwy.  At least we lose the routing information (where a
  743.   * message came from) at the moment.
  744.   */
  745.   oldNet = inNet;
  746.   inNet = NORMAL_NET;           /* cheat */
  747.   if ((domain = SearchList(&Serves, dir->Domain)) != NULL)
  748.     {
  749.     for (rover = 0; rover < dir->HighFile; rover++)
  750.       {
  751.       sPrintf(temp, "%d", rover);
  752.       MakeDomainFileName(buffer, dir->MapDir, temp);
  753.       if ((netMisc = safeopen(buffer, READ_ANY)) != NULL)
  754.         {
  755.         getMsgStr(getNetChar, nodeId, NAMESIZE);
  756.         getMsgStr(getNetChar, nodeName, NAMESIZE);
  757.         NormStr(nodeId);
  758.         NormStr(nodeName);
  759.         for (c = nodeName; *c; c++)
  760.         if (*c == '_') *c = ' ';
  761.         /* first check against ourselves (!) */
  762.         if (RouteHere(nodeId, nodeName, domain))
  763.           {
  764.           getRoom(MAILROOM);
  765.           StartDecode(ReadRoutedDest);
  766.           RCount = SCount = 0;
  767.           NetCharSource = ReadRouted;
  768.           while (getMessage(ReadRouted, TRUE, TRUE, TRUE))
  769.             {
  770.             msgBuf.mbaddr[0] = 0;       /* just in case */
  771.             inRouteMail();
  772.  
  773.             }
  774.           NetCharSource = getNetChar;
  775.           fclose(netMisc);
  776.           unlink(buffer);
  777.           dir->UsedFlag = TRUE;
  778.           continue;
  779.  
  780.           }
  781.         fclose(netMisc);
  782.         if (AcceptRoute(nodeId, nodeName))
  783.           {
  784.           strCpy(nodeId, netTemp.netId);
  785.           FindRouteSlot();
  786.           /* kludge around a bug (does it exist anymore?) */
  787.           if (netTemp.nbHiRouteInd < 0) netTemp.nbHiRouteInd = 0;
  788.           sPrintf(temp, "R%d.%d", RouteSlot, netTemp.nbHiRouteInd++);
  789.           makeSysName(newfn, temp, &cfg.netArea);
  790.           MoveFile(buffer, newfn);      /* use system dep */
  791.           if ((netMisc = safeopen(newfn, R_W_ANY)) != NULL)
  792.             {
  793.             fprintf(netMisc, "%-20s", nodeId);
  794.             fclose(netMisc);
  795.  
  796.             }
  797.           netTemp.nbflags.HasRouted = TRUE;
  798.           putNet(RouteSlot, &netTemp);
  799.           dir->UsedFlag = TRUE;
  800.  
  801.           }
  802.  
  803.         }
  804.  
  805.       }
  806.  
  807.     }
  808.   inNet = oldNet ;
  809.  
  810.   }
  811. /*
  812. * SetCallout()
  813. *
  814. * For some domain with outstanding mail, find out what system we'll be
  815. * sending that mail to and setup that value.
  816. */
  817. void SetCallout(DomainDir *data)
  818.   {
  819.   data->TargetSlot = SetUpCallOut(data->Domain);
  820.  
  821.   }
  822. /*
  823. * SetUpCallOut()
  824. *
  825. * This is responsible for discovering what system should be called for
  826. * delivering mail to the designated domain.  It returns the index of the
  827. * node to receive the domain mail (whether final destination or simply a
  828. * transshipper).  If we serve the domain then return Error.
  829. *
  830. * NB: This is an interface function to the routines which actually handle
  831. * setting the proper call out flags and returning the proper index.  The
  832. * function itself initializes the data structure for the search (by
  833. * resetting flags in the DomainHandlers list) and then calling something
  834. * else to conduct the search.  This structure is called for due to the
  835. * recursive nature of the search.
  836. */
  837. void ClearSearched(DomainHandler *Domain);
  838. static int SetUpCallOut(char *DName)
  839.   {
  840.   RunList(&DomainHandlers, ClearSearched);      /* clears searched flag */
  841.   return CallOutWork(DName);            /* do possibly recursive work   */
  842.  
  843.   }
  844. /*
  845. * CallOutWork()
  846. *
  847. * This does actual work of SetUpCallOut().  This is separated from the
  848. * calling function because we want to modularize the actual search ability
  849. * from the callers, but we must clear the search flags of the list once.
  850. * Since recursion is employed to follow the links of the 'via' pointers,
  851. * we are forced to this measure.
  852. *
  853. * Oh, yes.  This function searches for the domain handler responsible for
  854. * the given domain.  If not found, we use the MailHub designee as the
  855. * recipient of this domain mail.  If found, it then tries to find if we
  856. * connect directly with that server.  If so, we set the domain mail call
  857. * out flag for that node and return the node's index to the caller.  If we
  858. * don't connect directly (i.e., node is not in the list), then we try to
  859. * follow the 'via' pointers until a connection is found.  If never found,
  860. * then use the MailHub, otherwise use and return the found node.
  861. *
  862. * If we serve the domain, return ERROR.
  863. *
  864. * We use the search flag in each element of the DomainHandler's list to
  865. * prevent "infinite recursion" syndrome.
  866. */
  867. static int CallOutWork(char *DName)
  868.   {
  869.   DomainHandler *Domain;
  870.   UNS_16 Slot;
  871.   extern int RouteSlot;
  872.   if (WeServe(DName) != NULL) return ERROR;
  873.   if ((Domain = SearchList(&DomainHandlers, DName)) != NULL)
  874.     {
  875.     if ((RouteSlot = searchNet(Domain->nodeId, &netTemp)) != ERROR)
  876.       {
  877.       DomainFlags[Slot = FindRouteSlot()] = TRUE;
  878.       return (int) Slot;        /* and get out now */
  879.  
  880.       }
  881.  
  882.     }
  883.   /*
  884.   * if we've searched this node before then we're in a loop and had
  885.   * better stop.  We handle the if clause this way as most efficient.
  886.   */
  887.   if (Domain != NULL && !Domain->searched)
  888.     {
  889.     /* if a "via" is known, trace it */
  890.     Domain->searched = TRUE;    /* infinite loop vaccine */
  891.     if (Domain != NULL && Domain->via != NULL)
  892.       {
  893.       return (int)CallOutWork(Domain->via->domain);     /* recurse it */
  894.  
  895.       }
  896.  
  897.     }
  898.   else if (Domain != NULL && Domain->searched)
  899.     {
  900.     printf("Loop detected\n");
  901.  
  902.     }
  903.   /* unknown hub or domain -> mailhub */
  904.   if (cfg.MailHub != 0)
  905.     {
  906.     if ((RouteSlot = searchNameNet(cfg.codeBuf + cfg.MailHub, &netTemp))
  907.     != ERROR)
  908.       {
  909.       DomainFlags[Slot = FindRouteSlot()] = TRUE;
  910.       return (int) Slot;        /* and get out now */
  911.  
  912.       }
  913.  
  914.     }
  915.   return (int)ERROR;
  916.  
  917.   }
  918. /*
  919. * ClearSearched()
  920. *
  921. * Work function to clear the search field of a domain handler.
  922. */
  923. void ClearSearched(DomainHandler *Domain)
  924.   {
  925.   Domain->searched = FALSE;
  926.  
  927.   }
  928. static int DMCount;
  929. static char LCheck;     /* groan -- inadequacy of list processing */
  930. /*
  931. * DomainOut()
  932. *
  933. * This function is tasked with sending all domain mail to the current system
  934. * we're connected to that is destined for that system.  Actually, it just
  935. * cycles through all current domains and lets another function handle the
  936. * real work.
  937. */
  938. int DomainOut(char LocalCheck)
  939.   {
  940.   void SendDomainMail();
  941.   LCheck = LocalCheck;
  942.   DMCount = 0;
  943.   RunList(&DomainMap, SendDomainMail);
  944.   return DMCount;
  945.  
  946.   }
  947. /*
  948. * SendDomainMail()
  949. *
  950. * This does the actual work of sending the mail.  It cycles through all the
  951. * mail in the given domain's directory, sending each piece in sequence.
  952. * Rejected mail, if any, is kept for another try later, and later processing
  953. * will close up any "holes" left in the numerical naming sequence for mail
  954. * files.  That same later processing will also kill empty directories.
  955. */
  956. void SendDomainMail(DomainDir *data)
  957.   {
  958.   DOMAIN_FILE buffer;
  959.   int rover, result;
  960.   label temp, Id, Name;
  961.   if (!gotCarrier()) return;
  962.   /* This domain is to be delivered to current system? */
  963.   if (data->TargetSlot == thisNet)
  964.     {
  965.     data->UsedFlag = TRUE;
  966.     for (rover = 0; rover < data->HighFile; rover++)
  967.       {
  968.       sPrintf(temp, "%d", rover);
  969.       MakeDomainFileName(buffer, data->MapDir, temp);
  970.       if ((result = SendRouteMail(buffer, data->Domain, Id, Name, LCheck))
  971.       == GOOD_SEND)
  972.         {
  973.         unlink(buffer);
  974.         DMCount++;
  975.  
  976.         }
  977.       else if (result == REFUSED_ROUTE)
  978.         {
  979.         sPrintf(msgBuf.mbtext, "Domain mail for %s _ %s not accepted by %s.",
  980.         Name, data->Domain, netBuf.netName);
  981.         netResult(msgBuf.mbtext);
  982.  
  983.         }
  984.  
  985.       }
  986.  
  987.     }
  988.  
  989.   }
  990. /*
  991. * SystemInSecondary()
  992. *
  993. * This looks for the given system in the secondary lists.  If a domain
  994. * was specified then just return almost immediately.
  995. */
  996. char SystemInSecondary(char *Name, char *Domain, char *dup)
  997.   {
  998.   int rover;
  999.   char *sep;
  1000.   SYS_FILE secondary;
  1001.   label name;
  1002.   char WorkName[(NAMESIZE * 2) + 1];
  1003.   char SearchSecondary(char *secondary,char *Name,char *Domain,char *isdup);
  1004.   strCpy(WorkName, Name);
  1005.   /* is the domain specified already?  if so, parse it */
  1006.   if ((sep = strchr(WorkName, '_')) != NULL ||
  1007.   (sep = strchr(WorkName, '.')) != NULL)
  1008.     {
  1009.     *sep++ = 0;
  1010.     NormStr(WorkName);
  1011.     NormStr(sep);
  1012.     if (strchr(sep, '_') != NULL ||
  1013.     strchr(sep, '.') != NULL)
  1014.     return FALSE;       /* no subdomains */
  1015.     if (strLen(sep) < 1) return FALSE;
  1016.     strCpy(Name, WorkName);
  1017.     strCpy(Domain, sep);
  1018.     *dup = FALSE;               /* by definition */
  1019.     return TRUE;
  1020.  
  1021.     }
  1022.   Domain[0] = 0;
  1023.   for (rover = 0; rover < 100; rover++)
  1024.     {
  1025.     sPrintf(name, "nodes%d.fst", rover);
  1026.     makeSysName(secondary, name, &cfg.netArea);
  1027.     if (access(secondary, 0) != 0) break;
  1028.     if (SearchSecondary(secondary, Name, Domain, dup)) break;
  1029.  
  1030.     }
  1031.   strCpy(WorkName, Name);
  1032.   /* make sure we found something and it's not us */
  1033.   return (char)( (Domain[0] != 0 &&
  1034.   strCmpU(Name, cfg.codeBuf + cfg.nodeName) != SAMESTRING &&
  1035.   strCmpU(UseNetAlias(WorkName,FALSE), cfg.codeBuf + cfg.nodeName)
  1036.   != SAMESTRING));
  1037.  
  1038.   }
  1039. /*
  1040. * SearchSecondary()
  1041. *
  1042. * This does the actual work of searching a secondary list for a system.
  1043. */
  1044. char SearchSecondary(char *secondary,char *Name,char *Domain,char *isdup)
  1045.   {
  1046.   FILE *fd;
  1047.   int  bucket;
  1048.   char found, *tab = NULL, *c, *tab2 = NULL;
  1049.   char line[90];
  1050.   JumpInfo JumpTable[BUCKETCOUNT];
  1051.   if ((fd = fopen(secondary, READ_ANY)) == NULL)    return FALSE;
  1052.   fread(line, VERS_SIZE + 1, 1, fd);
  1053.   fread(JumpTable, sizeof JumpTable, 1, fd);
  1054.   #ifdef IS_MOTOROLA
  1055.   for (bucket = 0; bucket < BUCKETCOUNT; bucket++)  Intel32ToMotorola(&JumpTable[bucket].offset);
  1056.   #endif
  1057.   bucket = (isdigit(Name[0])) ? Name[0] - '0' :
  1058.   toUpper(Name[0]) - 'A' + 10;
  1059.   fseek(fd, JumpTable[bucket].offset, 0);
  1060.   found = FALSE;
  1061.   do
  1062.     {
  1063.     *isdup = FALSE;
  1064.     if (fgets(line, sizeof line, fd) == NULL) break;
  1065.     if ((tab2 = strchr(line, '\n')) != NULL)
  1066.     if( tab2 )*tab2 = 0;
  1067.     if (strlen(line) == 0)
  1068.       {
  1069.       break;
  1070.  
  1071.       }
  1072.     if (line[0] <= ' ')
  1073.       {
  1074.       switch (line[0])
  1075.         {
  1076.         case DUP:
  1077.         *isdup = TRUE;
  1078.         break;
  1079.         default: printf("Ooop!");
  1080.         break;
  1081.  
  1082.         }
  1083.       c = line + 1;
  1084.  
  1085.       }
  1086.     else c = line;
  1087.     tab = strchr(c, '\t');
  1088.     if( tab )*tab++ = 0;
  1089.     if (strCmpU(c, Name) == 0)
  1090.     found = TRUE;
  1091.     if (strCmpU(c, Name) > 0) break;
  1092.  
  1093.     }
  1094.   while (!found);
  1095.   if (found)
  1096.     {
  1097.     if ((tab2 = strchr(tab, '\t')) != NULL)
  1098.     if( tab2 )*tab2++ = 0;
  1099.     strCpy(Domain, tab);
  1100.     if (tab2 != NULL)    /* alias?  Copy it into search string */
  1101.     strCpy(Name, tab2);
  1102.  
  1103.     }
  1104.   fclose(fd);
  1105.   return found;
  1106.  
  1107.   }
  1108. /*
  1109. * EatCosts()
  1110. *
  1111. * This function eats a line from ctdlcost.sys and returns a structure
  1112. * containing the cost suitable for inclusion into a list.
  1113. */
  1114. static void *EatCosts(char *line)
  1115.   {
  1116.   NumToString *data;
  1117.   char *c;
  1118.   if ((c = strchr(line, ' ')) == NULL) return NULL;
  1119.   *c++ = 0;
  1120.   if (strCmpU(line, "Unknown") == SAMESTRING)
  1121.     {
  1122.     UnknownCost = atoi(c);
  1123.     return NULL;
  1124.  
  1125.     }
  1126.   data = GetDynamic(sizeof *data);
  1127.   data->string = strdup(line);
  1128.   data->num = atoi(c);
  1129.   return data;
  1130.  
  1131.   }
  1132. /*
  1133. * FindCost()
  1134. *
  1135. * This finds the cost of sending mail to a given domain.
  1136. */
  1137. UNS_16 FindCost(char *domain)
  1138.   {
  1139.   UNS_16 *data;
  1140.   if ((data = SearchList(&Costs, domain)) == NULL)
  1141.   return UnknownCost;
  1142.   return *data;
  1143.  
  1144.   }
  1145. /*
  1146. * WriteDomainContents()
  1147. *
  1148. * This writes the secondary list in readable format by reading NODES*.RAW.
  1149. */
  1150. void WriteDomainContents()
  1151.   {
  1152.   int rover;
  1153.   SYS_FILE secondary;
  1154.   label name;
  1155.   int   count = 0;
  1156.   char  line[80], vers[VERS_SIZE + 1];
  1157.   char  work[80], *c;
  1158.   FILE *fd, *fd2;
  1159.   extern char *READ_TEXT;
  1160.   for (rover = 0; rover < 100; rover++)
  1161.     {
  1162.     sPrintf(name, "nodes%d.raw", rover);
  1163.     makeSysName(secondary, name, &cfg.netArea);
  1164.     if ((fd = fopen(secondary, READ_TEXT)) == NULL)
  1165.       {
  1166.       break;
  1167.  
  1168.       }
  1169.     /* make sure the raw version genned the fst version */
  1170.     sPrintf(name, "nodes%d.fst", rover);
  1171.     makeSysName(secondary, name, &cfg.netArea);
  1172.     if ((fd2 = fopen(secondary, READ_ANY)) == NULL)
  1173.       {
  1174.       fclose(fd);
  1175.       continue;
  1176.  
  1177.       }
  1178.     GetAString(line, 80, fd);   /* gets version line */
  1179.     fread(vers, 1, VERS_SIZE, fd2);
  1180.     vers[VERS_SIZE] = 0;
  1181.     fclose(fd2);
  1182.     if (strCmpU(line, vers) != SAMESTRING)
  1183.       {
  1184.       fclose(fd);
  1185.       continue;
  1186.  
  1187.       }
  1188.     while (GetAString(line, 80, fd) != NULL)
  1189.       {
  1190.       if (strncmp(line, ".domain", 7) == SAMESTRING)
  1191.         {
  1192.         if (count != 0) doCR();
  1193.         strCpy(work, strchr(line, ' ') + 1);
  1194.         if ((c = strchr(work, ' ')) != NULL) *c = 0;
  1195.         doCR();
  1196.         count = 0;
  1197.         mPrintf("In domain %s", strchr(line, ' ') + 1);
  1198.         if (FindCost(work) != 0)
  1199.         mPrintf(" (%d LD credits):", FindCost(work));
  1200.         doCR();
  1201.  
  1202.         }
  1203.       else
  1204.         {
  1205.         if (strchr(line, ':') != NULL) continue;
  1206.         NormStr(line);
  1207.         if (strLen(line) == 0) continue;
  1208.         mPrintf("%s", line);
  1209.         if (++count % 3 == 0)
  1210.           {
  1211.           count = 0;
  1212.           doCR();
  1213.  
  1214.           }
  1215.         else
  1216.           {
  1217.           #ifdef TURBO_C_VSPRINTF_BUG
  1218.           SpaceBug(28 - strLen(line));   /* EEEESH */
  1219.           #else
  1220.           mPrintf("%*c", 28 - strLen(line), ' ');
  1221.           #endif
  1222.  
  1223.           }
  1224.  
  1225.         }
  1226.  
  1227.       }
  1228.     if (count != 0) doCR();
  1229.     doCR();
  1230.     fclose(fd);
  1231.  
  1232.     }
  1233.  
  1234.   }
  1235. /*
  1236. * DomainLog()
  1237. *
  1238. * This writes out a message to the domain log.
  1239. */
  1240. static void DomainLog(char *str)
  1241.   {
  1242.   SYS_FILE name;
  1243.   char work[200];
  1244.   extern SListBase Errors;
  1245.   sPrintf(work, "(%s %s) %s", formDate(), Current_Time(), str);
  1246.   makeSysName(name, "domain.log", &cfg.domainArea);
  1247.   CallMsg(name, work);
  1248.   if (inNet == NON_NET)
  1249.     {
  1250.     AddData(&Errors, strdup(str), NULL, FALSE);
  1251.  
  1252.     }
  1253.   else
  1254.   netResult(str);               /* netResult() will add time/date stuff */
  1255.  
  1256.   }
  1257. /*
  1258. * RouteHere()
  1259. *
  1260. * Returns true if the mail is meant for this installation.
  1261. */
  1262. char RouteHere(char *Id, char *Name, char *Domain)
  1263.   {
  1264.   label temp1;
  1265.   char *c;
  1266.   extern label HomeId;
  1267.   normId(Id, temp1);
  1268.   if (strCmpU(temp1, HomeId) == SAMESTRING) return TRUE;
  1269.   if (!normId(Id, temp1))
  1270.     {
  1271.     strCpy(temp1, Name);
  1272.     for (c = temp1; *c; c++)
  1273.     if (*c == '_') *c = ' ';
  1274.     if ((Domain == NULL ||
  1275.     strCmpU(Domain, cfg.codeBuf + cfg.nodeDomain) == SAMESTRING ||
  1276.     WeServe(Domain) != NULL) &&
  1277.     (strCmpU(cfg.codeBuf + cfg.nodeName, Name) == SAMESTRING ||
  1278.     strCmpU(cfg.codeBuf + cfg.nodeName,
  1279.     UseNetAlias(Name, FALSE)) == SAMESTRING))
  1280.     return TRUE;
  1281.  
  1282.     }
  1283.   return FALSE;
  1284.  
  1285.   }
  1286. /*
  1287. * LocalName()
  1288. *
  1289. * This function takes a string of form <system> _ <domain> and attempts to
  1290. * discover if this domain mapped system is actually a local.  This is used
  1291. * when we're sending mail and are trying to find out if a Who Else override
  1292. * needs to be generated.  Ugly  kludge, but, hey, that's what programming's
  1293. * all about, eh?
  1294. */
  1295. char *LocalName(char *system)
  1296.   {
  1297.   char *domain, *System;
  1298.   if ((domain = strchr(system, '_')) == NULL) return system;
  1299.   domain += 2;  /* always preceded by a space -- or so we assume */
  1300.   if (strCmpU(domain, cfg.codeBuf + cfg.nodeDomain) == SAMESTRING ||
  1301.   WeServe(domain) != NULL)
  1302.     {
  1303.     System = strdup(system);
  1304.     if ((domain = strchr(System, ' ')) == NULL)
  1305.     return system;      /* should never happen, though */
  1306.     *domain = NULL;
  1307.     if (searchNameNet(System, &netTemp) != ERROR)
  1308.       {
  1309.       free(System);
  1310.       return netTemp.netName;
  1311.  
  1312.       }
  1313.     free(System);
  1314.  
  1315.     }
  1316.   return system;
  1317.  
  1318.   }
  1319. /*
  1320. * lifo()
  1321. *
  1322. * Universal function for causing Last In First Out lists to occur in the
  1323. * SList stuff.
  1324. */
  1325. static int lifo()
  1326.   {
  1327.   return 1;
  1328.  
  1329.   }
  1330.